﻿namespace Example
{
    using System.ServiceModel;
    using System.ServiceProcess;

    public partial class ExampleService2 : ServiceBase
    {
        public ExampleService2()
        {
            InitializeComponent();
        }

        public ServiceHost ServiceHost { get; set; }

        protected override void OnStart(string[] args)
        {
            OnStop();
            ServiceHost = new ServiceHost(typeof(Service2));
            ServiceHost.Open();
        }

        protected override void OnStop()
        {
            if (null == ServiceHost)
            {
                return;
            }

            ServiceHost.Close();
            ServiceHost = null;
        }
    }
}